package com.example.forjava.entity;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class StreamUtil {

    public static void main(String[] args) {
        List<Integer> ids = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            ids.add(i);
        }
        new Thread(() -> exec(ids, "A")).start();

       // sleep(2000);

        new Thread(() -> exec(ids, "B")).start();
    }

    private static void exec(List<Integer> ids, String flag) {
        ids.parallelStream().forEach(integer -> {
            log.info("Flag: {} ,Id: {}", flag, integer);
            sleep(1000);
        });
    }

    public static void sleep(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
